package com.example.demo.service;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import com.example.demo.constants.API;
import com.example.demo.tools.HttpUtil;
import com.google.gson.JsonObject;

public class RegistryService {

    private HttpUtil httpUtil;

    public RegistryService(){
        httpUtil = new HttpUtil();
    }



    public void registry(String name, String password,String nickname, Handler handler){
        JsonObject json = new JsonObject();
        json.addProperty("name",name);
        json.addProperty("password",password);
        json.addProperty("nickname",nickname);
        String data = json.toString();
        new Thread(new Runnable() {
            @Override
            public void run() {
                String json = httpUtil.sendRequestByPost(API.REGISTRY_URL, data);
                //子线程返回数据到主线程
                Message msg = new Message();
                Bundle bundle = new Bundle();
                bundle.putString("result",json);
                msg.setData(bundle);
                //子线程发送数据
                handler.sendMessage(msg);
            }
        }).start();
    }


}
